package gui.BeginDialogue;

import java.awt.Dialog;
import java.awt.FileDialog;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class LoadFilePanel extends JPanel implements ActionListener{

	private static final long serialVersionUID = -6565213962928410277L;

	private IBeginDialog ibg;
	private JTextField textField = new JTextField(20);
	private JButton button = new JButton("Parcourrir");
	private ButtonSetMode bsm;
	private Dialog owner;
	private GameInformation gi;
	
	public void loadFile() throws ChargementException{
		if(bsm.isSelected())
			gi.chargeConcourt(textField.getText());
	}
	
	public LoadFilePanel(IBeginDialog dialog , Dialog owner,GameInformation g){
		gi=g;
		this.owner=owner;
		ibg=dialog;
		setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
		JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT));
		bsm = new ButtonSetMode("Charger Concourt",false,ibg);
		aux.add(bsm);
		add(aux);
		aux = new JPanel(new FlowLayout(FlowLayout.CENTER));
		aux.add(textField);
		button.addActionListener(this);
		aux.add(button);
		add(aux);
	}
	
	public void block(){
		textField.setEditable(bsm.isSelected());
		button.setEnabled(bsm.isSelected());
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		FileDialog fd = new FileDialog(owner,"Fichier a charger", FileDialog.LOAD);
		fd.setVisible(true);
		if((fd.getDirectory()!=null)&&(fd.getFile()!=null))
				textField.setText(fd.getDirectory()+fd.getFile());
	}
}
